    <div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <% $.et.load('template/menu.et.html', data) %>
            <div class="header">
                <h3 class="text-muted">
                    WebMCS
                </h3>
            </div>
            <div class="jumbotron well">
                <h1>
                     欢迎使用WebMCS！
                </h1>
                <p class="lead">
                       <% if(data.username == null){ %>
                       要管理Minecraft服务器请先登陆你的账号
                       <% }else{ %>
                       欢迎您，<% p(data.username) %>。点击<a href='javascript:;' onclick='route.go("template/serverstatus.et.html")'>状态</a>开始管理你的Minecraft服务器吧！<a href='javascript:;' onclick='R.logout();'>注销登陆</a>
                       <% } %>
                </p>
                <% if(data.username == null){ %>
                <p>
                    <a class="btn btn-lg btn-success" href="javascript:;" onclick="R.login_click();" role="button">登陆</a>
                </p>
                <% } %>
            </div>
            <div class="panel panel-default">
            <div class="panel-heading">
                <h2 class="panel-title">常见问题</h2>
            </div>
            <div class="panel-body">
                <h4>我发现了BUG/有好的建议，如何反馈？</h4>
                <p>见更多-意见反馈，在网页种评论即可</p>
                <p>如果BUG涉及安全/隐私问题不便公开，可以发送邮件到 webmcs@pppploi8.me 进行反馈</p>
                <hr />
                <h4>我忘记了密码，应该如何重置？</h4>
                <p>请在关闭WebMCS的前提下删除password.key文件，然后开启WebMCS，即可重新设置初始密码。</p>
                <hr />
                <h4>提示WARN Unable to instantiate ... WindowsAnsiOutputStream警告是怎么回事？</h4>
                <p>这是因为开服工具需要接收Minecraft服务端控制台消息导致的正常提示，不用理会。</p>
                <hr />
                <h4>开服后显示没有主清单属性/找不到主类？</h4>
                <p>请安装正确的服务端文件，请不要把Minecraft客户端或者其他东西当作服务端安装！</p>
                <hr />
                <h4>开服后只有少量提示，然后显示服务器关闭</h4>
                <p>你的服务端版本可能不支持Java8，请在设置中更换Java7重试</p>
                <hr />
                <h4>开服后提示Error occurred during initialization of VM，然后显示服务器已关闭</h4>
                <p>请在设置中把内存设置改为0让Java自动分配</p>
                <hr />
                <h4>开服后提示Run the command /fml confirm or or /fml cancel to proceed.</h4>
                <p>请在状态页输入/fml confirm，一直到不弹出提示为止</p>
            </div>
            <div class="panel-footer"><% $.et.load('template/version.et.html') %></div>
            </div>
        </div>
        </div>
    </div>
    <!-- 模态窗口 -->
    <!-- 模态框（Modal） -->
    <div class="modal fade" id="login_modal" tabindex="-1" role="dialog" 
       aria-labelledby="myModalLabel" aria-hidden="true">
       <div class="modal-dialog">
          <div class="modal-content">
             <div class="modal-header">
                <button type="button" class="close" 
                   data-dismiss="modal" aria-hidden="true">
                      &times;
                </button>
                <h4 class="modal-title">
                       登陆
                </h4>
             </div>
             <div class="modal-body">
                <div style="margin-bottom: 10px;" class="input-group input-group-lg">
                    <span class="input-group-addon">账号</span>
                    <input id="username" type="text" class="form-control" placeholder="账号">
                </div>
                <div class="input-group input-group-lg" style="margin-bottom: 10px;">
                    <span class="input-group-addon">密码</span>
                    <input id="password" type="password" class="form-control" placeholder="密码">
                </div>
                <div class="input-group input-group-lg">
                    <span class="input-group-addon">验证码</span>
                    <input id="code" type="text" class="form-control" placeholder="验证码">
                    <span class="input-group-addon" style="padding: 0"><img id="codeImg" onclick="R.flushCode()" style="height: 44px;" /></span>
                </div>
                <div style="margin-top: 10px;margin-left: 5px;" style="margin-bottom: 10px;">
                <input id="saveLoginStatus" type="checkbox" />勾选此项7天内自动登陆
                </div>
             </div>
             <div class="modal-footer">
                <button type="button" class="btn btn-default" 
                   data-dismiss="modal">关闭
                </button>
                <button onclick="R.login()" type="button" class="btn btn-primary">
                      登陆
                </button>
             </div>
          </div>
         </div>
    </div>
    <div class="modal fade" id="first_modal" tabindex="-2" role="dialog" 
       aria-labelledby="myModalLabel" aria-hidden="true">
       <div class="modal-dialog">
          <div class="modal-content">
             <div class="modal-header">
                <button type="button" class="close" 
                   data-dismiss="modal" aria-hidden="true">
                      &times;
                </button>
                <h4 class="modal-title">
                       首次使用
                </h4>
             </div>
             <div class="modal-body">
                <h4>检测到您是第一次使用，请先设置账号密码：</h4>
                <div class="input-group input-group-lg" style="margin-bottom: 10px;">
                    <span class="input-group-addon">设置账号</span>
                    <input id="name" type="text" class="form-control" placeholder="账号">
                </div>
                <div class="input-group input-group-lg" style="margin-bottom: 10px;">
                    <span class="input-group-addon">设置密码</span>
                    <input id="pwd" type="password" class="form-control" placeholder="密码">
                </div>
                <div class="input-group input-group-lg" style="margin-bottom: 10px;">
                    <span class="input-group-addon">确认密码</span>
                    <input id="c_pwd" type="password" class="form-control" placeholder="重复密码">
                </div>
                <div style="margin-top: 10px;margin-left: 5px;" style="margin-bottom: 10px;">
                <input id="eula" type="checkbox" />
                我已阅读并遵守<a href="https://account.mojang.com/documents/minecraft_eula" target="_blank">《Minecraft最终用户许可协议》</a>
                </div>
             </div>
             <div class="modal-footer">
                <button type="button" class="btn btn-default" 
                   data-dismiss="modal">关闭
                </button>
                <button onclick="R.init()" type="button" class="btn btn-primary">
                      设置
                </button>
             </div>
          </div>
         </div>
    </div>
    <script>
        R.logout = function(){
            webmcs.login.logout(function(){
                route.setUsername(null);
                route.go('template/index.et.html');
            });
        }
        
        R.login_click = function(){
            webmcs.login.isInit(function(data){
                if(data.isfirst){
                    $('#first_modal').modal("show");
                }else{
                    $('#login_modal').modal("show");
                }
            });
        }
        
        R.init = function(){
            var name = $("#name").val();
            var pwd = $("#pwd").val();
            var eula = $("#eula").prop("checked");
            if (name=="" || pwd==""){
                common.showMsg("请输入账号和密码！");
                return;
            }
            if (pwd!=$("#c_pwd").val()){
                common.showMsg("两次输入的密码不一致！");
                return;
            }
            if (eula==false){
                common.showMsg("请接受Minecraft最终用户许可协议！");
                return;
            }
            webmcs.login.register(name, pwd, function(data){
                if(data.status){
                    $('#first_modal').modal("hide");
                    setTimeout(function(){
                            route.setUsername(name);
                            route.go('template/index.et.html');
                    },500);
                }else{
                    common.showMsg("注册失败");
                }
            });
        }
        
        R.flushCode = function(){
            $("#codeImg").attr("src","login/image.login?r="+Math.random()+"&token="+webmcs.getToken());
        }
        
        R.login = function(){
            var name = $("#username").val();
            var pwd = $("#password").val();
            var code = $("#code").val();
            var saveStatus = $('#saveLoginStatus').prop('checked');
            if (name=="" || pwd=="" || code==""){
                common.showMsg('登陆失败，请填写账号密码和验证码！');
                return;
            }
            webmcs.login.login(name, pwd, code, saveStatus, function(data){
                if (data.status){
                    $('#login_modal').modal('hide');
                    setTimeout(function(){
                        route.setUsername(name);
                        route.go('template/index.et.html');
                    },500);
                }else{
                    switch(data.msg){
                        case "CODEERROR":
                            common.showMsg("登陆失败，验证码错误！");
                            break;
                        case "CHECKERROR":
                               common.showMsg("登陆失败，请检查账号或密码！");
                            break;
                        case "NETERROR":
                            common.showMsg("登录失败，网络错误！");
                            break;
                        default:
                            common.showMsg("发生未知错误，请反馈BUG！");
                            break;
                    }
                    $('#code').val('');
                    R.flushCode();
                }
            });
        }
        
        R.flushCode();
        </script>
